<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%@ page import="BaseDAO.*,Entity.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    This is my JSP page. <br>
    <!-- 求素数的方法 -->
    <%
    	int sum=0;
    	for( int count=0 ,i=2;i<=100;i++){
    		for(int j=2;j<=i;j++){
    		if(i%j==0)
    			count++;
    		}
    		if(count==1)
    		 sum+=i;
    		 
    		 count=0;
    	}
    	out.println(sum);
     %>
     <%!int geshu(){
      int count = 0;
		for(int i =2000;i<=2013;i++){
		    if((i%4==0&&i%100!=0)||i%400==0){
		        count++;
		    }
		}
     return count;
     }
      %>
      <!-- 记住表达式后面不能添加分号 -->
      <%=geshu()%> 
    <%
		    int count = 0;
		for(int i =2000;i<=2013;i++){
		    if((i%4==0&&i%100!=0)||i%400==0){
		        count++;
		    }
		}
	 out.print(count);
    
     %>
     
  <%--	Connection conn = null;
		PreparedStatement stmet = null;
		ResultSet rs = null;
		// 加载驱动
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		// 建立连接
		try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/prictise1", "root", "123");
			// PreparedStatement与Connection之间的连接方式
			String st = "select * from grade";
			stmet = conn.prepareStatement(st);
			rs = stmet.executeQuery();
			//jsph中的换行其实就是HTML的换行，在页面中输出</br>然后容器将其翻译成HTML语言
			out.print("</br>");
			// 循环显示查询结果
			while (rs.next()) {
				String a=rs.getInt(1) + "-------------" + rs.getString(2);
				out.print(a);
--%><br>
		<%--	}

		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} 
 --%>
 
 <% 
 	//JDBCUtils ju=new JDBCUtils();
 	out.print("你好");
 	%>
 	<br/>
 	<% 
 	List<Grade> gg=JDBCUtils.grade();
 	for(Grade g:gg){
 	%>
 	<%=g.getId()%>,<%=g.getGname()%>
 	<br/>
 	<%
 	}
 	 %>
<%
	out.print("分页信息如下");
	out.print("<br/>");
	List<Student> list=JDBCUtils.find(2);
	for(Student st:list){
		%>
		<%=st.getStuno()%>........<%=st.getSname()%>.........<%=st.getEnterdate()%>......<%=st.getGradeid() %>
		<br/>
	<%
	}
	%>
  </body>
</html>
